package com.gzc.just.play.last.war.common.share.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * All-in-One模式自动配置类
 * 根据类路径和配置条件自动装配相应的组件
 */
@Configuration
@Import({
    AllInOneConfig.class,
    DataAccessConfig.class,
    SQLiteDataSourceConfig.class
})
public class AutoConfiguration {
    
    /**
     * SQLite数据源自动配置
     */
    @Configuration
    @ConditionalOnClass(name = "org.sqlite.JDBC")
    @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "dev-all-in-one")
    static class SQLiteAutoConfiguration {
        
        @Bean
        @ConditionalOnMissingBean
        public SQLiteDataSourceConfig sqliteDataSourceConfig() {
            return new SQLiteDataSourceConfig();
        }
    }
    
    // Caffeine缓存配置已在DataAccessConfig中定义，此处不再重复定义
    
    /**
     * 开发环境自动配置
     */
    @Configuration
    @ConditionalOnProperty(name = "all-in-one.enabled", havingValue = "true", matchIfMissing = true)
    static class DevelopmentAutoConfiguration {
        
        @Bean
        @ConditionalOnMissingBean
        public AllInOneConfig.DevelopmentConfig developmentConfig() {
            return new AllInOneConfig.DevelopmentConfig();
        }
    }
    
    /**
     * 生产环境自动配置
     */
    @Configuration
    @ConditionalOnProperty(name = "spring.profiles.active", havingValue = "prod")
    static class ProductionAutoConfiguration {
        
        @Bean
        @ConditionalOnMissingBean
        public AllInOneConfig.ProductionConfig productionConfig() {
            return new AllInOneConfig.ProductionConfig();
        }
    }
}
